var add_repair_data = function () {
    $.ajax({
        url: "repair/detail",
        type: "post",
        data: {
            "token": localStorage['token'],
            "id": localStorage['id'],
        },
        success: function (data) {
            if (data.code == 200) {
                $("#phone").val(data.data.phone);
                $("#name").val(data.data.name);
            } else {
                errorMessage(data.msg);
            }
        }
    })
};
$("#changeSelf_repair").click(function () {
    var loadDiv = load("#body", 999999);
    var name = $("#name").val();
    var phone = $("#phone").val();
    $.ajax({
        url: "repair/update",
        type: "post",
        data: {
            "token": localStorage['token'],
            "id": localStorage['id'],
            "name": name,
            "phone": phone,
        },
        success: function (data) {
            if (data.code == 200) {
                load_close(loadDiv);
                var url = "/page/repair/home";
                $("#body").load(url);
                // console.log($("#user"));
                // $("#user").children("span").val(name + ",欢迎");
                localStorage['username'] = name;
                window.location.reload();
                setTimeout(function () {
                    message("请求成功", "", "success", 2000);
                }, 500);

            } else {
                errorMessage(data.msg);
            }
        }
    })
});
$("#phone").blur(function () {
    var test = /^1[34578]\d{9}$/;
    var phone = $(this).val();
    if (!test.test(phone)) {
        $(this).parent().children(".errorMsg").text("请输入正确的手机号");
    } else {
        $(this).parent().children(".errorMsg").empty();
    }
    if (phone == "") {
        $(this).parent().children(".errorMsg").text("手机号不能为空");
    }
});

$("#phone,#name").blur(function () {
    if ($("#phone").parent().children(".errorMsg").text() != "" || $("#name").parent().children(".errorMsg").text() != "") {
        $("#changeSelf_repair").attr("disabled", "disabled");
        $("#changeSelf_repair").addClass("button_cannot");
    } else {
        $("#changeSelf_repair").removeAttr("disabled");
        $("#changeSelf_repair").removeClass("button_cannot");
    }
});

